home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1186 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: 102642.2026@compuserve.com (Ja Uhm)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to dynamically allocate first element of linked list.
  5. Date: 11 Jan 1996 23:59:54 GMT
  6. Organization: soflogic
  7. Message-ID: <4d489q$7qg@dub-news-svc-5.compuserve.com>
  8. References: <erkDL007G.rt@netcom.com>
  9. NNTP-Posting-Host: ad45-164.compuserve.com
  10. X-Newsreader: WinVN 0.90.5
  11.  
  12. In article <erkDL007G.rt@netcom.com>, erk@netcom.com (Staugher) says:
  13. >
  14. >Im trying (without any luck )to write a function to allocate the first element 
  15. >of a doubly linked list in C++. Unfortunately I learned data structures in 
  16. >Pascal and have to port my knowledge (or lack of ) to C.
  17. >
  18. >Here is my arrangement:
  19. >
  20. >
  21. >struct elmnt
  22. >        { char name[20];
  23. >          char number[17];
  24. >          struct elmnt *forward_pointer;
  25. >          struct elmnt *reverse_pointer;
  26. >        }
  27. >
  28. >newptr = malloc(sizeof(struct elmnt));
  29.  
  30.  
  31. You must cast the return from malloc to the type (elmnt *) .
  32.  
  33. Therefore use:
  34.  
  35. newptr = (elmnt *) malloc(sizeof(struct elmnt));
  36.  
  37.  
  38.                        Ja Uhm
  39.